package com.super8.super8newtv;


import android.app.Activity;
import android.os.Bundle;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.super8.super8newtv.api.ApiContract;
import com.super8.super8newtv.api.ApiError;
import com.super8.super8newtv.api.ApiService;
import com.super8.super8newtv.api.parser.ResponseBeanParser;
import com.super8.super8newtv.bean.NoticeBean;
import com.super8.super8newtv.bean.ResponseBean;
import com.super8.super8newtv.bean.ResponseVideoBean;
import com.super8.super8newtv.bean.VideoBaseInfo;
import com.super8.super8newtv.utils.LogUtils;

import java.util.List;

public class TVHomeActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tvhome);
        getVideoList(1,1,20);
    }



    /**
     * 获取公告语
     */
    private void getVideoList(int category,int pageNum,int pageSize) {
        String url="http://onlearning.cn:8000/do-list?";//?category=1&pageNum=2&pageSize=3   http://onlearning.cn/     39.99.141.46
        if (pageNum<=0)
            pageNum=1;
        url+="pageNum="+pageNum;
        if (pageSize<=0)
            pageNum=10;
        url+="&pageSize="+pageSize;
        if (category>0)
            url+="&category="+category;

        LogUtils.e("getVideoList", "===="+url);
        ResponseBeanParser<List<VideoBaseInfo>> responseBeanParser = new ResponseBeanParser<List<VideoBaseInfo>>(new TypeToken<ResponseBean<List<VideoBaseInfo>>>() {
        }.getType());
        ApiService.getInstance().get(url, "", responseBeanParser, new ApiContract.OnResponseListener<List<VideoBaseInfo>>() {
            @Override
            public void onSuccess(ResponseBean<List<VideoBaseInfo>> result) {
                if (result.getCode()==200) {//获取成功
                    LogUtils.e("getVideoList", result.getData().size()+"==========="+new Gson().toJson(result.getData()));
//                    if (!result.getData().isEmpty()) {
//                        lsNoticeBean = result.getData();
//                        Message message = Message.obtain();
//                        message.what = 1;
//                        mHandler.sendMessage(message);
//                    }
                }
            }

            @Override   //刷新token异常
            public void onError(ApiError error) {
                LogUtils.e("getVideoList ", "获取视频信息onError:" + error.getErrorMessage());
            }
        });
    }


}
